package org.codegallery.javagal.xml.transformation;

import org.codegallery.javagal.Constants;

import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

/**
 * Created by IntelliJ IDEA.
 * User: gongwenwei
 * Date: 11-10-14
 * Time: 下午1:33
 * To change this template use File | Settings | File Templates.
 */
public class XMLTransform {
    public static void main(String[] args) {
            XMLTransform tr=new XMLTransform();
            tr.transform();
    }

    public void transform() {
        try {
            String foler= Constants.TEST_RES_DIR+"\\xsltsample\\";
            String xmlFile = foler+"sample1.xml";
            String styleFile =foler+ "sample1.xsl";
            StreamSource source = new StreamSource(xmlFile);
            StreamSource styleSource = new StreamSource(styleFile);

            TransformerFactory factory = TransformerFactory.newInstance();
            Transformer transformer = factory.newTransformer(styleSource);

            StreamResult result = new StreamResult(System.out);
            transformer.transform(source, result);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
